package com.hy.demo.ui.fragment;

import android.os.Bundle;
import android.text.TextUtils;

import androidx.annotation.Nullable;
import androidx.recyclerview.widget.RecyclerView;

import com.hy.demo.R;
import com.hy.demo.app.BaseFragment;
import com.hy.demo.util.MenuViewUtil;

public class MenuFragment extends BaseFragment {
    private RecyclerView rcyList;
    private String title = null;
    private int xmlId = 0;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        if (getArgs() != null) {
            xmlId = getArgs().getInt(MenuViewUtil.ARG_XML);
            title = getArgs().getString(MenuViewUtil.ARG_TITLE);
        }
    }

    @Override
    protected boolean isSingleLayout() {
        return TextUtils.isEmpty(title);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.v_rcy;
    }

    @Override
    protected void initView() {
        rcyList = findViewById(R.id.rcy_rcyList);
    }

    @Override
    protected void initData() {
        if (title != null)
            setTitle(title);
        MenuViewUtil.attach(rcyList, xmlId, this);
    }

    public static MenuFragment newInstance(int xmlId, @Nullable String title) {
        MenuFragment fragment = new MenuFragment();
        Bundle bundle = new Bundle();
        bundle.putInt(MenuViewUtil.ARG_XML, xmlId);
        bundle.putString(MenuViewUtil.ARG_TITLE, title);
        fragment.setArguments(bundle);
        return fragment;
    }

}
